<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="true" border="false">
                    <div class="table-operator">
                        <rx-button alias="sysWordTemplateAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <rx-button v-if="editEnable && selectedRowKeys.length > 0" alias="sysWordTemplateEdit"
                                   :butn-icon="'edit'"
                                   :butn-type="'primary'" :show-no-right="false" @click="editOne">{{$ti18('rxList.editBtn','编辑')}}
                        </rx-button>

                        <a-dropdown v-if="removeEnable && selectedRowKeys.length > 0">
                            <rx-button alias="sysWordTemplateDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                       :show-no-right="false" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}
                            </rx-button>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="$ti18('rxForm.name','名称')">
                                    <a-input :placeholder="$ti18('rxForm.name','名称','','input')" v-model="queryParam.Q_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.temName','模版名称')">
                                    <a-input :placeholder="i18n('form.temName','模版名称')" v-model="queryParam.Q_TEMPLATE_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :bordered="isBorder"
                    :defaultPageSize="10"
                    url="/api-system/system/core/sysWordTemplate/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                  <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                    <span v-if="editEnable && record.templateId && showBtn(false)" @click="previewDialog(record)">{{$ti18('rxList.previews','预览')}}</span>
                    <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                  </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
    import SysWordTemplateApi from '@/api/system/core/sysWordTemplate'
    import SysWordTemplateEdit from './SysWordTemplateEdit'
    import {BaseList,TokenUtil} from "@lowcode/jpaas-common-lib";
    import {ntkoBrowser} from "@/components/iweboffice/officecontrol/ntkobackground.min.js";

    export default {
        name: 'SysWordTemplateList',
        mixins: [BaseList],
        data() {
            return {
                columns: [
                    {
                        title: this.$ti18('rxList.index', '序号'),
                        type: 'indexColumn',
                        width: 60,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'}
                    },
                    {title: this.$ti18('rxForm.name','名称'), dataIndex: 'name', width: 100},
                    {title: this.i18n('form.dataSource','数据源'), dataIndex: 'dsAlias', width: 100},
                    {title: this.i18n('form.temName','模版名称'), dataIndex: 'templateName', width: 100},
                    {title: this.$ti18('rxForm.describe','描述'), dataIndex: 'description', width: 100},
                    { title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', sorter:true,sortField:'CREATE_TIME_', width: 120},
                    {title: this.$ti18('rxList.action','操作'), width: 60, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
                ],
                component: SysWordTemplateEdit,
                comment: this.i18n('list.docTemEdit','文档模板编辑')
            }
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "sysWordTemplate", key);
            },
            previewDialog(record) {
                var self = this;
                this.$layer.prompt({
                    title: this.i18n('enterKey','请输入查询主键pk：'),
                    area: ['300px', '200px']
                }, function (value) {
                    self.previewWord(record.templateId, value);
                    self.$layer.close(this.id);
                })
            },
            previewWord(templateId, id) {
                let ntkoed = ntkoBrowser.ExtensionInstalled(); //判断插件是否安装
                var accessToken = TokenUtil.getToken();
                if (ntkoed) {
                    var url = "/office/ntkoofficepreview?officeId=" + templateId + "&id=" + id + "&accessToken=" + accessToken;
                    ntkoBrowser.openWindow(url, true);
                }
            },
            delById(ids) {
                return SysWordTemplateApi.del({ids: ids.join(',')});
            },
            getListByParams(parameter) {
                return SysWordTemplateApi.query(parameter)
            },
            closeSearchbar() {
                //关闭过滤弹窗；（点击X触发）
                this.fitSearch = false;
            },
            search() {
                this.$refs.table.loadData();
            },
            cancel() {
                this.resetSearch();
            }
        }
    }
</script>
<style scoped>

</style>

